package com.biz.primus.ms.product.trans;

import com.biz.primus.base.enums.SaleChannel;
import com.biz.primus.base.vo.commodity.ProductFinalPriceVo;
import com.biz.primus.commodity.vo.frontend.ProductDetailResult;
import com.biz.primus.ms.product.interfaces.ProductPrototype;

import java.util.function.Function;

/**
 * @author jiangnan
 * @Description:
 */
public class ProductPrototype2ProductDetailResult implements Function<ProductPrototype,ProductDetailResult> {
    @Override
    public ProductDetailResult apply(ProductPrototype productPrototype) {
        ProductDetailResult respVo = new ProductDetailResult();
        respVo.setProductId(productPrototype.getProductId());
        respVo.setProductCode(productPrototype.getProductCode());
        respVo.setName(productPrototype.getProductName());
        respVo.setLogo(productPrototype.getLogo());
        respVo.setPackageNumber(productPrototype.getProductBaseVo().getPackageNumber());
        respVo.setSaleStatus(productPrototype.getProductBaseVo().saleStatus(SaleChannel.APP));
        respVo.setWarehouseQuantity(productPrototype.getStock());
        respVo.setQuantity(productPrototype.getDepotStock());
        ProductFinalPriceVo productFinalPriceVo = productPrototype.getProductFinalPriceVo();
        if (productFinalPriceVo != null){
            respVo.setPrice(productFinalPriceVo.getFinalPrice());
            respVo.setFclSinglePrice(productFinalPriceVo.getFclSinglePrice());
            respVo.setEWalletPrice(productFinalPriceVo.getEWalletPrice());
            respVo.setMarketPrice(productFinalPriceVo.getFinalMarketPrice());
        }
        respVo.setPredictTime(productPrototype.getPredictTime());
        respVo.setPromotionBasicInfoVos(productPrototype.getPromotionBasicInfoVos());
        return respVo;
    }

}
